<?php

defined('SYSPATH') or die('Access error!');

class Model_User_Privilege extends Model
{

    public $rules = array(
        'name' => array
            (
            'not_empty' => null,
        )
    );

    /**
     *  根据parent_id 获取某个分类下的列表
     * @param type $id
     * @return type
     */
    public function get_privilege_list($where_arr = '', $params = '*')
    {
        $this->order_by(array('position' => 'ASC', 'id' => 'DESC'));
        $privilege_list_temp = $this->get_results2($where_arr, $params);
        $privilege_list = array();
        if (Arr::validate_arr($privilege_list_temp))
        {
            foreach ($privilege_list_temp as $key => $value)
            {
                $value['cn_name'] = __($value['name']);
                $privilege_list[] = $value;
            }
        }
        return $privilege_list;
    }

    public function get_privilege_col($where = '', $params = '*')
    {
        $privilege_list = $this->get_privilege_list($where, $params);
        if (Arr::validate_arr($privilege_list[0]) > 0)
        {
            $privilege_id_list = Arr::pluck($privilege_list, 'id');
        }
        return Arr::validate_arr($privilege_id_list) ? $privilege_id_list : array();
    }

    public function get_privilege_option($id = 0, $selectid = 0)
    {
        $option_list = $this->get_privilege_list(array('parent_id' => $id));
        if (Arr::validate_arr($option_list))
        {
            $option_str = '<selete>';
            foreach ($option_list as $key => $value)
            {
                
            }
        }
    }

    public function get_privilege_arr()
    {
        //获取缓存文件
        return $this->get_category_cache_option('privilege');
    }

}